// Copyright 2009 StarCite Inc.  All rights reserved.
// Producer.java 3:19:38 PM danny.liu
package com.billowsoft.sample.thread.nolock;

/**
 * @author danny.liu Apr 18, 2012
 * @version 1.0
 * 
 */
public class Producer extends Thread {

	private ProductFactory factory;

	public Producer(ProductFactory factory) {
		this.factory = factory;
	}

	@Override
	public void run() {
		int pNumber = 0;
		while (true) {
			synchronized (factory) {
				Product product = new Product(++pNumber);
				factory.createProduct(product);

				Product product2 = new Product(++pNumber);
				factory.createProduct(product2);
				
				factory.notifyAll();
			}

			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}
